using System.ComponentModel.DataAnnotations;

namespace JGSY.CMS.LowCode.Platform.Infrastructure.Configuration.Models;

/// <summary>
/// 数据库配置映射
/// </summary>
public class DatabaseConfiguration
{
    [Required]
    public string DatabaseType { get; set; } = "SqlServer";

    [Required]
    public ConnectionStringsConfiguration ConnectionStrings { get; set; } = new();
    
    public DatabaseExtraConfiguration Database { get; set; } = new();
}

/// <summary>
/// 连接字符串配置
/// </summary>
public class ConnectionStringsConfiguration
{
    public string SqlServer { get; set; } = string.Empty;
    public string MySql { get; set; } = string.Empty;
    public string Postgres { get; set; } = string.Empty;
    public string Sqlite { get; set; } = string.Empty;

    /// <summary>
    /// 根据数据库类型获取连接字符串
    /// </summary>
    /// <param name="databaseType">数据库类型</param>
    /// <returns>连接字符串</returns>
    public string GetConnectionString(string databaseType)
    {
        return databaseType.ToLower() switch
        {
            "sqlserver" => SqlServer,
            "mysql" => MySql,
            "postgres" or "postgresql" => Postgres,
            "sqlite" => Sqlite,
            _ => SqlServer
        };
    }
}

/// <summary>
/// 数据库额外配置
/// </summary>
public class DatabaseExtraConfiguration
{
    public string Url { get; set; } = string.Empty;
    public int ConnectionTimeout { get; set; } = 30;
    public int CommandTimeout { get; set; } = 30;
    public int MaxRetryCount { get; set; } = 3;
    public bool EnableDetailedErrors { get; set; } = false;
    public bool EnableSensitiveDataLogging { get; set; } = false;
}
